home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 19 / madtrb11.zip / INKEY.INC < prev    next >
Text File  |  1985-07-13  |  2KB  |  46 lines

  1. {INKEY.INC}
  2. FUNCTION InKey(VAR special : BOOLEAN; VAR KeyChar : CHAR) : BOOLEAN;
  3.  
  4. (*
  5. An emulation of the $INKEY function provided in BASIC. InKey returns
  6. TRUE if a key has been pressed. If the parameter Special is also TRUE,
  7. then the character is one of the 2-code keys (like F1-F10), and the
  8. parameter returned in KeyChar is the code for the second key.
  9.  
  10. If you want "type-ahead" buffering of keystrokes, you must turn off
  11. the compiler "C" directive {$C-}. If not, DOS will discard keystrokes
  12. which haven't yet been read in.
  13.  
  14. Source: "INKEY: A Multiple Keypress Function", TUG Lines Volume I Issue 4
  15. Author: Orville Jenkins/Panther Associates/Dallas-Ft. Worth, Texas/
  16. Application: MS-DOS, PC-DOS
  17. *)
  18.  
  19. var
  20.  dosrec : record ax,bx,cx,dx,bp,si,di,ds,es,flags : integer; end;
  21.  
  22. begin
  23.  if keypressed                     {  Does DOS say char is ready?          }
  24.   then   { A key was pressed }
  25.   begin { inkey processing }
  26.    dosrec.ax := $0800;             {  Tell DOS console input without echo  }
  27.    msdos(dosrec);                  {  Call DOS                             }
  28.    keychar := chr(lo(dosrec.ax));  {  Pull char from AL                    }
  29.    inkey := true;                  {  Tell caller yes, it's a keystroke    }
  30.    if ord(keychar) = 0             {  Is it a 2-code key?                  }
  31.     then  { It was }
  32.     begin
  33.      special := true;              {  Let caller know it's a 2-code key    }
  34.      dosrec.ax := $0800;           {  Get the other character              }
  35.      msdos(dosrec);
  36.      keychar := chr(lo(dosrec.ax));
  37.     end
  38.     else special := false;         {  Wasn't a 2-code key                  }
  39.   end
  40.   else   { No key was pressed }
  41.   begin
  42.    inkey := false;                 {  Tell caller there was no key pressed }
  43.    special := false;               {  and reset special key flag           }
  44.   end;
  45.  end; {InKey}
  46.